<?php
include("../config/connect.php");
include("../public/common.php");

function GetLastKey( $url, $key )
{
	$key .= "=";
	$nStart = stripos( $url, $key );
	if( $nStart !== false )
	{
		$nStart += strlen( $key );
		return htmlspecialchars(base64_decode(substr( $url, $nStart )), ENT_QUOTES );
	}
	return "";
}

$p = base64_decode( CheckUrlParamNoDie( "p" ) );
$p = EnCode( $p, "_goshopping_" );
$p = "&" . $p;

$discount = GetKey($p, "discount");
$tb_id = GetKey($p, "tb_id");
$item_id = GetKey($p, "item_id");
$trade_id = GetKey($p, "trade_id");
$ip = gethostbyname($_SERVER["REMOTE_ADDR"]);
$use_discount = GetKey($p, "use_discount");
$info = GetLastKey( $p, "info" );
$app = GetLastKey( $p, "app" );

$sql = "insert into trade(tb_id, discount, trade_id, item_id, ip, use_discount, info, app) values('$tb_id', '$discount', '$trade_id', '$item_id', '$ip', '$use_discount', '$info', '$app')";

$result = mysql_query( $sql );
if( $result )
{
	ReturnTrue();
}
else 
{
	ReturnFalse("添加失败。");
}
?>